﻿using CommonUtils;
using CommonUtils.Models;

namespace DatabaseService.DatabaseDAO
{
    /// <summary>
    /// 数据库抽象类继承
    /// 继承的类需要有显式构造函数
    /// </summary>
    public abstract class TableModelMapper : ModelBase
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 构造初始化mapper目录
        /// </summary>
        public TableModelMapper()
        {
            if (PathManager.IsUseMapperXMLFile)
            {
                //this.fileName = $@"Mapper\{this.GetType().Namespace}\{this.GetType().Name}.xml";
                this.fileName = $@"Mapper\{this.GetType().Name}.xml";
            }
            else
            {
                //默认放在程序集的Mapper文件夹下
                var thistype = this.GetType();
                this.fileName = $@"{thistype.Namespace}.Mapper.{thistype.Name}.xml";
            }
        }

        /// <summary>
        /// mapper目录路径
        /// </summary>
        protected string fileName { get; set; }

        /// <summary>
        /// 获取mapper目录路径
        /// </summary>
        /// <returns></returns>
        public virtual string GetMappperPath()
        {
            return this.fileName ?? "";
        }
    }
}
